const {BaseService} = require('../../basic.js')
const {
	JobModel
} = require('dx-func-entity')

module.exports = class Job extends BaseService {
	constructor(ctx) {
		super(ctx);
		this.entity = JobModel;		
	}
	getCount(where){
		return this.where(where).count();
	}
	getJobs(where){
		return this.where(where).limit(100).select();
	}
	company() {
	    //  hasOne('表名称','外键名','主键名')，绑定字段到主数据
		return this.hasOne('human-company', 'company_id', '_id').bindField({
			company_name: 'name',
			company_contract:'contract',
			company_email:'email',
			hrlist:'hrlist'
		});
	}
	hr() {
	    //  hasOne('表名称','外键名','主键名')，绑定字段到主数据
		return this.hasOne('human-talent', 'hr_id', '_id').bindField({
			hr_name: 'name',
			hr_job:'job'
		});
	}
	hrobj(){
	    //  hasOne('表名称','外键名','主键名')，绑定字段到主数据
		return this.hasOne('human-talent', 'hr_id', '_id').field('name,job,_id');
	}
	async updateCMerge({_id,_ids}){
		const result = await this.where({'company_id':['in',_ids]}).update({
			company_id:_id
		});
		
		return result;
	}
	async updateTMerge({_id,_ids}){
		const result = await this.where({'hr_id':['in',_ids]}).update({
			hr_id:_id
		});
		return result;
	}
	async findById(_id){
		return await this.where({_id}).with(['company','hr']).find();
	}
}
